import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from "@nestjs/common";
import { Response } from "express";

// 异常过滤器
@Catch(HttpException)
export class HttpFilter implements ExceptionFilter{
    catch(exception: HttpException, host: ArgumentsHost) {
        const ctx=host.switchToHttp()
        const response=ctx.getResponse<Response>()
        const status=exception.getStatus()
        response.status(status).json({
            data:{
                message:exception.message,
                status
            },
            success:false,
        })
    }
}